package Proxy;

import net.sf.cglib.proxy.Enhancer;

/**
 * @author xinxing
 * @date 2023/2/6 17:07
 */
public class CglibFactory {

    public static Object getProxy(Object target) {
        Enhancer enhancer = new Enhancer();
        // 类加载器
        enhancer.setClassLoader(target.getClass().getClassLoader());
        // 父类为实例类
        enhancer.setSuperclass(target.getClass());
        // 方法拦截器
        enhancer.setCallback(new CglibProxyHandler());
        // 创建代理类
        return enhancer.create();

    }

}
